function qs(ele) {
    return document.querySelector(ele)
}

// 接口地址：https://www.apifox.cn/apidoc/shared-36f0cbc0-9064-44bc-850a-805e263bf494/api-25827426
axios.defaults.baseURL = 'http://124.223.14.236:3001/api'
// obj 传值
// address 数据中对应的编号属性名
// id id名
// hint 提示
// num 默认
async function fn(url, obj, address, id, hint, num) {
    const { data: { data } } = await axios.get(url, { params: obj })
    const str = data.map(item => `<option value="${item[address]}">${item.name}</option>`).join('')
    qs(`#${id}`).innerHTML = `<option value="">${hint}</option>` + str
    qs(`#${id}`).value = num
}

fn('/city/province', '', 'province', 'province', '请选择省份', '34')
fn('/city/city', { provinceCode: '34' }, 'city', 'city', '请选择城市', '01')
fn('/city/area', { provinceCode: '34', cityCode: '01' }, 'area', 'county', '请选择区县', '02')


qs(`#province`).addEventListener('change', () => {
    fn('/city/city', { provinceCode: qs('#province').value }, 'city', 'city', '请选择城市', '')
    qs('#county').innerHTML = '<option value="">请选择区县</option>'
})
qs(`#city`).addEventListener('change', () =>
    fn('/city/area', { provinceCode: qs('#province').value, cityCode: qs('#city').value }, 'area', 'county', '请选择区县', '')
)

